from strategy.strategy1 import RandomBuyStrategy, RandomStrategy, RandomStrategySpot
from trade.backtest import BackTestModel
from trade.broker.simulate import BrokerSimulate


def main_backtest():
    simulate = BrokerSimulate(
        init_balances={"USDT": {"total": 100000, "debt": 0}},
        slip_rate=0.0001,
        leverages={"BTC/USDT:USDT": 3.0, "USDT": 2.0, "BTC": 4.0},
    )
    strategy = RandomStrategy()
    backtest = BackTestModel(simulate, strategy)
    backtest.run_backtest("2024-01-01", "2024-02-28")


def main_backtest_future_1m():
    simulate = BrokerSimulate(
        init_balances={"USDT": {"total": 100000, "debt": 0}},
        slip_rate=0.0001,
        leverages={"BTC/USDT:USDT": 3.0, "USDT": 2.0, "BTC": 4.0},
    )
    strategy = RandomStrategy()
    backtest = BackTestModel(simulate, strategy)
    backtest.run_backtest("2024-01-01", "2024-06-30")


def main_backtest_spot():
    simulate = BrokerSimulate(
        init_balances={"USDT": {"total": 100000, "debt": 0}},
        slip_rate=0.0001,
        leverages={"BTC/USDT:USDT": 3.0, "USDT": 2.0, "BTC": 4.0, "BTC/USDT": 4.0},
    )
    strategy = RandomStrategySpot()
    backtest = BackTestModel(simulate, strategy)
    backtest.run_backtest("2024-01-01", "2024-06-30")


def main_backtest_random_spot_and_future():
    simulate = BrokerSimulate(
        init_balances={"USDT": {"total": 100000, "debt": 0}},
        slip_rate=0.0001,
        leverages={
            "BTC/USDT:USDT": 3.0,
            "BTC/USDT": 4.0,
            "ETH/USDT": 5.0,
            "FDUSD/USDT": 6,
            "USDC/USDT:USDT": 4.0,
            "USDT/USDT": 5.0,
            "USDC/USDT": 4.0,
        },
    )
    strategy = RandomBuyStrategy()
    backtest = BackTestModel(simulate, strategy)
    backtest.run_backtest("2024-01-01", "2024-06-30")


# def main_backtest_two_line():
#     simulate = BrokerSimulate(
#         init_balances={"USDT": {"total": 100000, "debt": 0}},
#         slip_rate=0.0000,
#         leverages={"USDT": 10.0, "ETH": 10.0},
#     )
#     symbol = "ETH/USDT"
#     simulate.datas[symbol]["ma7"] = (
#         simulate.datas[symbol]["close"]
#         .rolling(window=7, center=False, min_periods=7)
#         .mean()
#     )
#     simulate.datas[symbol]["ma25"] = (
#         simulate.datas[symbol]["close"]
#         .rolling(window=25, center=False, min_periods=25)
#         .mean()
#     )
#     strategy = TwoLineStrategy(symbol)
#     backtest = BackTestModel(simulate, strategy)
#     backtest.run_backtest("2024-01-01", "2024-06-30")


if __name__ == "__main__":
    main_backtest()
    # main_backtest_future_1m()
    # main_backtest_spot()
    # main_backtest_random_spot_and_future()
